﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Dextrys.SharePoint;
using Higer.SharePoint.HigerWebService;

namespace Higer.SharePoint.UserControls
{
    public partial class moreOrderTask : BaseUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //if (!IsPostBack)
            //{
            try
            {
                //DataTable dt_OrderTasks = GetOrderTasks("caoyang");
                DataTable dt_OrderTasks = GetOrderTasks(GetCurrentUserName(this.CurrentUser.LoginName));
                if (dt_OrderTasks != null && dt_OrderTasks.Rows.Count > 0)
                {
                    gvOrderTask.DataSource = dt_OrderTasks;
                    gvOrderTask.DataBind();
                    gvOrderTask.Visible = true;
                    lblMessage.Visible = false;
                }

            }
            catch (Exception ex)
            {
                gvOrderTask.Visible = false;
                lblMessage.Visible = true;
                lblMessage.Text = ex.Message;
            }

            //}
        }

        #region 属性

        #endregion

        #region 方法

        public string GetCurrentUserName(string loginName)
        {
            if (loginName.Contains('\\'))
            {
                loginName = loginName.Substring(loginName.IndexOf('\\') + 1);
            }
            return loginName;
        }

        public DataTable GetOrderTasks(string username)
        {
            HigerWorkList higerWorkList = new HigerWorkList();
            DataSet ds = higerWorkList.GetOrderTasks(username);
            if (ds != null && ds.Tables.Count > 0)
            {
                return ds.Tables[0];
            }
            else
            {
                return null;
            }

        }

       

        public string GetRequestDate(string requestDate)
        {
            string date = "";
            //date = t1.ToString("mm/dd") + "~" + t2.ToString("mm/dd");
            if (!requestDate.Equals(""))
            {
                try
                {
                    DateTime dtRequestDate = Convert.ToDateTime(requestDate);
                    requestDate = dtRequestDate.ToString("MM/dd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                }
                catch (Exception ex)
                {
                    throw ex;
                }

                date = requestDate + "(技术)";
            }

            return date;
        }

        public string GetFristLineDate(string fristLineDate)
        {
            string date = "";
            //date = t1.ToString("mm/dd") + "~" + t2.ToString("mm/dd");
            if (!fristLineDate.Equals(""))
            {
                try
                {
                    DateTime dtFristLineDate = Convert.ToDateTime(fristLineDate);
                    fristLineDate = dtFristLineDate.ToString("MM/dd", System.Globalization.DateTimeFormatInfo.InvariantInfo);
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            
                date = fristLineDate + "(生产)";
            }

            return date;
        }

        #endregion

        #region 事件

        protected void gvOrderTask_RowDataBound(object sender, GridViewRowEventArgs e)
        {

            if ((e.Row.RowIndex >= 0))
            {
                string requestdate = e.Row.Cells[4].Text;

                if (requestdate != null && requestdate != "" && requestdate != "&nbsp;")
                {
                    DateTime requestDate = Convert.ToDateTime(requestdate.ToString());

                    if (requestDate.CompareTo(DateTime.Today) > 0)
                    {
                        e.Row.CssClass = "myblackcss";
                    }
                    else if (requestDate.CompareTo(DateTime.Today) == 0)
                    {
                        e.Row.CssClass = "mygreencss";
                    }
                    else if (requestDate.CompareTo(DateTime.Today) < 0)
                    {
                        e.Row.CssClass = "myredcss";
                    }
                }
                else
                {
                    e.Row.CssClass = "myblackcss";
                }

            }

            //隐藏要求完成时间
            e.Row.Cells[4].Visible = false;
        }

        #endregion
    }
}